package com.myappengine.dao;

import javax.jdo.PersistenceManager;

import org.springframework.stereotype.Repository;

import com.google.appengine.api.datastore.KeyFactory;
import com.myappengine.model.Clazz;

@Repository
public class ClassDAO {
	
	public Clazz persistClass(Clazz clazz) {
		PersistenceManager pm = null;
		try {
			pm = PMF.getPersistenceManager().getPersistenceManager();
			return pm.makePersistent(clazz);
		} finally {
			pm.close();
		}
	}
	
	public void updateClass(Clazz clazz) {
		PersistenceManager pm = PMF.getPersistenceManager().getPersistenceManager();
		Clazz c = pm.getObjectById(Clazz.class, clazz.getKey());
		c.setClassId(clazz.getClassId());
		c.setClassName(clazz.getClassName());
		c.setStudents(clazz.getStudents());
		pm.close();
	}
}
